﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Microsoft.Practices.Unity;
using WebStore.Domain.Entities;
using WebStore.Domain.Entities.Enum;

namespace WebStore.Web.App.Utility.Helpers
{
    public static class RoleHelper
    {
        [Dependency]
        public static Entities Entities { get; set; }

        public static bool IsInRole(this HtmlHelper htmlHelper,params RoleType[] roles)
        {
            if (HttpContext.Current.User == null)
                return false;
            return
                Entities.Users.Any(
                    x => x.Email == HttpContext.Current.User.Identity.Name && x.UserRoles.Any(q => roles.Contains(q.Role.RoleType)));
        }
    }
}